/**
 * <pre>
 *     author : XML
 *     e-mail : 946891360@qq.com
 *     time   : 2019/06/10
 *     version:
 *     desc   :
 * </pre>
 */

import {applyMiddleware, createStore} from 'redux'
import thunk from 'redux-thunk'
import reducer from '../reducer'
import {middleware} from "../navigator/AppNavigator";

/**
 * 日志中间件
 * @param store
 * @returns {function(*): Function}
 */
const logger = store => next => action => {
    if (typeof action === 'function') {
        console.log('dispatching a function')
    } else {
        console.log('dispatching ', action)
    }
    const result = next(action);
    console.log('nextState', store.getState());
};
const middlewares = [
    middleware,
    logger,
    thunk,
];

/**
 * 创建store
 */
export default createStore(reducer, applyMiddleware(...middlewares));